{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1481\n"
     ]
    }
   ],
   "source": [
    "# 没有input字段，给加上。\n",
    "data_dir = \"/data/data/fintuning/llamafactory_input/ruozhiba_qa.json\"\n",
    "# 读取 JSONl 文件\n",
    "final_data = []\n",
    "# 读取 JSON 文件\n",
    "with open(data_dir, 'r') as f:\n",
    "    raw_data = json.load(f)\n",
    "    print(len(raw_data))\n",
    "for d in raw_data:\n",
    "    final_data.append(\n",
    "        {\n",
    "                \"instruction\": d[\"instruction\"],\n",
    "                \"input\": \"\",\n",
    "                \"output\": d[\"output\"]\n",
    "            }\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "json_dir = \"/data/data/fintuning/llamafactory_input/ruozhiba_processed.jsonl\"\n",
    "with open(json_dir, 'w', encoding=\"utf-8\") as f:\n",
    "    for item in final_data:\n",
    "        json.dump(item, f, ensure_ascii=False)\n",
    "        f.write('\\n')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
